﻿using Alos.IRepository;
using Alos.IService;
using PetaPoco;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Alos.Entity;
using Alos.Common;
using System.Threading.Tasks;

namespace Alos.Service
{
    public class ReObjectiveQuestionService : BaseService<ReObjectiveQuestion>, IReObjectiveQuestionService
    {
        IReTaskRepository ReTaskRepository;
        IReObjectiveQuestionRepository ReObjectiveQuestionRepository;
        public ReObjectiveQuestionService(IReObjectiveQuestionRepository _ReObjectiveQuestionRepository, IReTaskRepository _ReTaskRepository)
        {
            ReObjectiveQuestionRepository = _ReObjectiveQuestionRepository;
            ReTaskRepository = _ReTaskRepository;
        }
        /// <summary>
        /// 学生提交记录（客观题）
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool CreateKeGuan(List<ReObjectiveQuestion> ReObjectiveQuestion)
        {
            foreach (ReObjectiveQuestion item in ReObjectiveQuestion)
            {
                ReTestOption retest = ReTaskRepository.GetReTaskByResouceId(Convert.ToInt32(item.QuestionID));
                item.IsCorrect = retest.ConnectNumber.Equals(item.Answer) ? true : false;
            }
            return ReObjectiveQuestionRepository.CreateKeGuan(ReObjectiveQuestion);
        }
        /// <summary>
        /// 统计学生提交记录（客观题）
        /// </summary>
        /// <param name="ArrangeID">课程编号</param>       
        /// <returns></returns>
        public IEnumerable<dynamic> GetReObjectiveQuestionByArrangeID(int ArrangeID)
        {
            return ReObjectiveQuestionRepository.GetReObjectiveQuestionByArrangeID(ArrangeID);
        }
    }
}
